﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Profile;
using Gift.Model;
using Gift.Model.ENUM;
using Gift.DAL;

namespace WebSite.admin
{
    public partial class left : BaseAdmin
    {
        // Fields
        public string display1 = "";

        readonly adminlogin theAdminLogin = new adminlogin();
        readonly UserRuleRef theUserRuleRef = new UserRuleRef();
        readonly dalCompany theCompany = new dalCompany();
        readonly DALRule theRule = new DALRule();

        string _editUserUrl = string.Empty;

        public string EditUserUrl
        {
            get {
                    if (base.CompanyId != null && base.AdminTypeId != "1")
                    {
                        _editUserUrl = "/admin/company/CompanyManager.aspx?id=" + base.CompanyId;
                    }
                    else
                    {
                        _editUserUrl = "/admin/user/adduser.aspx?uid=" + base.AdminUserId;
                    } 
                  return _editUserUrl;
                }
        
        }



        //// Methods
        //private void Bind()
        //{
        //    if (this.Session["flags"].ToString() == "0")
        //    {
        //        this.display1 = "none;";
        //    }
        //}

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Session["Adminlogin"] == null)
            {
                base.Response.Write("<script language=javascript>window.top.location.href='login.aspx';</script>");
            }
            else if (!base.IsPostBack)
            {
              
                this.ValidateLoginRule();
            }
        }



         void ValidateLoginRule()
        {


            int iAdminId = theAdminLogin.GetIdByName(this.Session["Adminlogin"].ToString());

            if (base.AdminTypeId == "1") //业务员
            {
     
                this.trOpenCardManger.Visible = true;
                this.trCardManager.Visible = true;             

                this.trCompanyList.Visible = true;
                this.trCompanyManger.Visible = true;
                              
                this.trCardStat.Visible = true;
                this.trReporStat.Visible = true;
      
                this.trCompanyMoneyList.Visible = true;
                this.trCompanyManger.Visible = true;
                return;
            }

            tbCompany oCompany = theCompany.GetModelByAdminId(iAdminId);
            if (oCompany != null)
            {
                if (oCompany.IsDelete)
                {
                    base.Response.Write("<script language=javascript>alert('贵公司账号已被禁用，如使用请与客服联系！');window.top.location.href='login.aspx';</script>");
                    base.Response.End();
                }
                base.CompanyId = oCompany.Id.ToString();
                base.CompanyLevelId = oCompany.LevelId.ToString();

                DataSet ds0;
                ds0 = theUserRuleRef.GetListByAdminIdForCompany(iAdminId);
                if (ds0 != null && ds0.Tables.Count > 0)
                {
                    foreach (DataRow dr in ds0.Tables[0].Rows)
                    {
                        ERule oERule = (ERule)Enum.Parse(typeof(ERule), dr["CompanyRule"].ToString(), true);
                        switch (oERule)
                        {
                            case ERule.OpenCardManager:
                                this.trOpenCardManger.Visible = true;
                                this.trCardManager.Visible = true;
                                 break;
                            case ERule.CompanyList:
                                 if (int.Parse(base.CompanyLevelId) < 4)
                                 {
                                     this.trCompanyList.Visible = true;
                                     this.trCompanyManger.Visible = true;
                                 }
                                 break;
                            case ERule.AddCompany:
                                 if (int.Parse(base.CompanyLevelId) < 4)
                                 {
                                     this.trCompanyManger.Visible = true;
                                     this.trAddCompany.Visible = true;
                                 }
                                 break;
                            case ERule.CardStat:
                                 this.trCardStat.Visible = true;
                                 this.trReporStat.Visible = true;
                                 break;
                            case ERule.CompanyMoneyList:
                                this.trCompanyMoneyList.Visible = true;
                                this.trCompanyManger.Visible = true;
                                break;
                        }
                    }
                }
            }
            else
            {
                base.CompanyLevelId = "0";
            }

            DataSet ds;
            ds = theUserRuleRef.GetListByAdminId(iAdminId);
            if (ds != null && ds.Tables.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    ERule oERule = (ERule)Enum.Parse(typeof(ERule), dr["Name"].ToString(), true);
                    switch (oERule)
                    {
                        case ERule.AddAdmin:
                            this.trAddAdmin.Visible = true;
                            this.trAdminManager.Visible = true;
                            break;
                        case ERule.AddArticle:
                            this.trAddArticle.Visible = true;
                            this.trArticleManager.Visible = true;
                            break;
                        case ERule.AddArticleClass:
                            this.trAddArticleClass.Visible = true;
                            this.trArticleManager.Visible = true;
                            break;
                        case ERule.AddCompany:
                            this.trAddCompany.Visible = true;
                            this.trCompanyManger.Visible = true;
                            break;
                        case ERule.AddGiftCard:
                            this.trAddCard.Visible = true;
                            this.trCardManager.Visible = true;
                            break;
                        case ERule.AddMenu :
                            this.trAddMenu.Visible = true;
                            this.trSystemConfiguration.Visible = true;
                            break;
                        case ERule.AddMessage:
                            this.trAddMessage.Visible = true;
                            this.trSystemConfiguration.Visible = true;
                            break;
                        case ERule.AddNewProduct:
                            this.trAddNewProduct.Visible = true;
                            this.trProductManager.Visible = true;
                            break;
                        case ERule.AddOrder:
                            this.trAddOrder.Visible = true;
                            this.trOrderManager.Visible = true;
                            break;
                        case ERule.MeterialOrderAdd:
                            this.trMeterialOrderAdd.Visible = true;
                            this.trMeterialOrderAdd.Visible = true;
                            break;
                        case ERule.AddProductBrand:
                            this.trAddProductBrand.Visible = true;
                            this.trProductManager.Visible = true;
                            break;
                        case ERule.AddProductClass:
                            this.trAddProductClass.Visible = true;
                            this.trProductManager.Visible = true;
                            break;
                        case ERule.AddProfessionAreaType:
                            this.trAddProfessionAreaType.Visible = true;
                            this.trPromoteManager.Visible = true;
                            break;
                        case ERule.AddPromoteProduct:
                            this.trAddPromoteProduct.Visible = true;
                            this.trPromoteManager.Visible = true;
                            break;
                        case ERule.AddUser:
                            this.trAddUser.Visible = true;
                            this.trUserManager.Visible = true;
                            break;
                        case ERule.AdminList:
                            this.trAdminList.Visible = true;
                            this.trAdminManager.Visible = true;
                            break;
                        case ERule.ArticleClass:
                            this.trArticleClass.Visible = true;
                            this.trArticleManager.Visible = true;
                            break;
                        case ERule.ArticleList:
                            this.trArticleList.Visible = true;
                            this.trArticleManager.Visible = true;
                            break;
                        case ERule.CompainList:
                            this.trCompainList.Visible = true;
                            this.trOrderManager.Visible = true;
                            break;
                        case ERule.CompainType:
                            this.trCompainType.Visible = true;
                            this.trOrderManager.Visible = true;
                            break;
                        case ERule.CompanyList:
                            this.trCompanyList.Visible = true;
                            this.trCompanyManger.Visible = true;
                            break;
                        case ERule.DefaultBulletin:
                            this.trDefaultBulletion.Visible = true;
                            this.trSystemConfiguration.Visible = true;
                            break;
                        case ERule.FlashAdvertConfiguration:
                            this.trFlashConfiguration.Visible = true;
                            this.trSystemConfiguration.Visible = true;
                            break;
                        case ERule.LeaveWordClass:
                            this.trLeaveWordType.Visible = true;
                            this.trUserManager.Visible = true;
                            break;
                        case ERule.MessageManager:
                            this.trMessageManager.Visible = true;
                            break;
                        case ERule.OpenCardManager:
                            this.trOpenCardManger.Visible = true;
                            this.trCardManager.Visible = true;
                            break;
                        case ERule.OrderProcess:
                            this.trOrderProcess.Visible = true;
                            this.trOrderManager.Visible = true;
                            break;
                        case ERule.OrderQuery:
                            this.trOrderQuery.Visible = true;
                            this.trOrderManager.Visible = true;
                            break;
                        case ERule.ProductBrand:
                            this.trProductBrand.Visible = true;
                            this.trProductManager.Visible = true;
                            break;
                        case ERule.ProductClass:
                            this.trProuctClass.Visible = true;
                            this.trProductManager.Visible = true;
                            break;
                        case ERule.ProductDefaultParament:
                            this.trProductDefaultParament.Visible = true;
                            this.trProductManager.Visible = true;
                            break;
                        case ERule.ProductList:
                            this.trProductList.Visible = true;
                            this.trProductManager.Visible = true;
                            break;
                        case ERule.ProductRecycle:
                            this.trProductRecycle.Visible = true;
                            this.trProductManager.Visible = true;
                            break;
                        case ERule.ProfessionManager:
                            this.trProfessionAreaTypeManager.Visible = true;
                            this.trPromoteManager.Visible = true;
                            break;
                        case ERule.PromoteProductManager:
                            this.trPromoteProductManager.Visible = true;
                            this.trPromoteManager.Visible = true;
                            break;
                        case ERule.CardStat:
                            this.trReporStat.Visible = true;
                            this.trCardStat.Visible = true;
                            break;
                        case ERule.OrderStat:
                            this.trReporStat.Visible = true;
                            this.trOrderStat.Visible = true;
                            break;
                        case ERule.SelftConfiurationMenu:
                            this.trSelfConfigurationMenu.Visible = true;
                            this.trSystemConfiguration.Visible = true;
                            break;
                        case ERule.StoreConfiguration:
                            this.trStoreConfiguration.Visible = true;
                            this.trSystemConfiguration.Visible = true;
                            break;
                        case ERule.UserComment:
                            this.trUserCommemnt.Visible = true;
                            this.trProductManager.Visible = true;
                            break;
                        case ERule.UserLeaveWord:
                            this.trUserLeaveWord.Visible = true;
                            this.trUserManager.Visible = true;
                            break;
                        case ERule.UserList:
                            this.trUserList.Visible = true;
                            this.trUserManager.Visible = true;
                            break;
                        case ERule.CardType:
                            this.trCardManager.Visible = true;
                            this.trCardType.Visible = true;
                            break;
                        case ERule.ProfessionAreaType:
                            this.trSystemConfiguration.Visible = true;
                            this.trProfessionArea.Visible = true;
                            break;
                        case ERule.CardQuery:
                            this.trCardManager.Visible = true;
                            this.trCardQuery.Visible = true;
                            break;
                        case ERule.OrderCancel:
                            this.trOrderCancel.Visible = true;
                            this.trOrderManager.Visible = true;
                            break;
                        case ERule.CompanyPartner:
                            this.trPublishCompanyManager.Visible = true;
                            this.trPublishCompanyPartner.Visible = true;
                            break;
                        case ERule.CompanyMoneyList:
                              this.trCompanyMoneyList.Visible = true;
                             this.trCompanyManger.Visible = true;
                             break;
                        case ERule.OrderQuerySelf:
                             this.trOrderManager.Visible = true;
                             this.trOrderQuerySelf.Visible = true;
                             break;
                        case ERule.AddPublishCompany:
                             this.trPublishCompanyManager.Visible = true;
                             this.trAddPublishCompany.Visible = true;
                             break;
                        case ERule.PublishCompanyList:
                             this.trPublishCompanyManager.Visible = true;
                             this.trPublishCompanyList.Visible = true;
                             break;
                        case ERule.PublishCompanyMoneyList:
                             this.trPublishCompanyManager.Visible = true;
                             this.trPublishCompanyMoneyList.Visible = true;
                             break;
                    }
                }
            }
          
        }

    }
}